<template>
    <div class="goods-list">
        <div @click="getDetail(item.id)" class="goods-item" v-for="item in list" :key="item.id">
            <img :src=item.url alt="">
            <h1 class="title">{{item.title}}</h1>
            <div class="info">
                <div class="price">
                    <span class="now">￥{{item.new}}</span>
                    <span class="old">￥{{item.old}}</span>
                </div>
                <div class="sell">
                    <span>{{item.sell}}</span>
                    <span>剩{{item.remain}}件</span>
                </div>
            </div>
        </div>
        <mt-button type="danger" size="large" plain @click="loadMore">加载更多</mt-button>
    </div>
</template>
<script>
import {Toast} from 'mint-ui';
export default{
    data:function () {
        return{
            list:[],
            index:1,
        }
    },
    methods:{
        getDetail:function (id) {
            this.$router.push({name:"goodsinfo",params:{id}})
        },
        loadShopList:function () {
            this.$http.get('lib/interface7_shoplist.json').then((res)=>{
                if(res.body.status == "ok"){
                    res.body.shoplists[this.index -1].forEach((item)=>{
                        this.list.push(item);
                    });
                }
           });
        },
        loadMore:function () {
            if(this.index < 3){
                this.index++;
                this.loadShopList();
            }else{
                Toast({
                    message: '没有更多内容了',
                    position: 'bottom',
                    duration: 2000
                });
            }
        }
    },
    created:function () {
        this.loadShopList();
    }
}
</script>
<style lang="scss" scoped>
.goods-list{
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 8px;
}
.goods-item{
    width: 49%;
    border: 1px solid #ccc;
    box-shadow: 0 0 6px #999;
    margin-bottom: 5px;
    min-height: 212px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    img{
        width: 100%;
    }
    .title  {
        font-size: 14px;
        font-weight: bold;
        height: 30px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;/*显示几行*/
        overflow: hidden;
        margin-bottom: 5px;
        text-align: center;
        // display: inline-block;
        // vertical-align: middle;
        margin-top: 8px;
        // line-height: 30px;
    }
    .info{
        color: whitesmoke;
        background-color: rgb(228, 223, 223);
        font-size: 12px;
        padding: 3px;
        height: 55px;
        color: rgb(117, 116, 116);
        .price{
            margin-bottom: 8px;
            .now{
                color: red;
                font-weight: bold;
                font-size: 16px;
            }
            .old{
                text-decoration: line-through;
                font-size: 12px;
                margin-left: 10px;
            }
        }
        .sell{
            display: flex;
            justify-content: space-between;
        }
    }
}
</style>